﻿using AdverseEventReportSystem.BLL.SchedulingSystem;
using AdverseEventReportSystem.Core;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AdverseEventReportSystem.BLL.Scheduling
{
    /// <summary>
    /// 排班周期
    /// </summary>
   public class ScheduleCycleManager
    {
       /// <summary>
       /// 保存排班周期
       /// </summary>
       /// <param name="holidayTypeSetting"></param>
       /// <returns></returns>
       public static OperateResult SaveScheduleCycle(ScheduleCycle scheduleCycle)
       {
           OperateResult resultInfo = new OperateResult();
           try
           {
               SchedulingSystemSoapClient service = new SchedulingSystemSoapClient();
               ResultHelperOfBoolean result = service.SaveSchedule(scheduleCycle);
               if (result.S)
               {
                   resultInfo.Result = 1;
                   resultInfo.Body = result.M;
               }
               else
               {
                   resultInfo.Result = 0;
                   resultInfo.Body = result.M;
               }
           }
           catch (Exception ex)
           {
               resultInfo.Result = 0;
               resultInfo.Body = ex.Message;
           }
           return resultInfo;

       }

       /// <summary>
       /// 获取排班周期列表
       /// </summary>
       /// <param name="pageIndex">页索引</param>
       /// <param name="pageSize">页大小</param>
       /// <returns></returns>
       public static OperateResult GetScheduleCycleList(int pageIndex, int pageSize)
       {
           OperateResult resultInfo = new OperateResult();
           try
           {
               SchedulingSystemSoapClient service = new SchedulingSystemSoapClient();
               ResultHelperOfString result = service.GetScheduleListForPage(pageIndex, pageSize);
               if (result.S)
               {
                   resultInfo.Result = 1;
                   resultInfo.Body = result.D;
               }
               else
               {
                   resultInfo.Result = 0;
                   resultInfo.Body = result.M;
               }
           }
           catch (Exception ex)
           {
               resultInfo.Result = 0;
               resultInfo.Body = ex.Message;
           }
           return resultInfo;
       }
       /// <summary>
       /// 获取单个排班周期
       /// </summary>
       /// <param name="id"></param>
       /// <returns></returns>
       public static OperateResult GetScheduleCycle(int id)
       {
           OperateResult resultInfo = new OperateResult();
           try
           {
               SchedulingSystemSoapClient service = new SchedulingSystemSoapClient();
               ResultHelperOfScheduleCycle result = service.GetSchedule(id);
               if (result.S)
               {
                   resultInfo.Result = 1;
                   resultInfo.Body = result.D;
               }
               else
               {
                   resultInfo.Result = 0;
                   resultInfo.Body = result.M;
               }
           }
           catch (Exception ex)
           {
               resultInfo.Result = 0;
               resultInfo.Body = ex.Message;
           }
           return resultInfo;
       }
       /// <summary>
       /// 删除排班周期
       /// </summary>
       /// <param name="id"></param>
       /// <returns></returns>
       public static OperateResult DelScheduleCycle(int id)
       {
           OperateResult resultInfo = new OperateResult();
           try
           {
               SchedulingSystemSoapClient service = new SchedulingSystemSoapClient();
               ResultHelperOfBoolean result = service.DelSchedule(id);
               if (result.S)
               {
                   resultInfo.Result = 1;
                   resultInfo.Body = result.M;
               }
               else
               {
                   resultInfo.Result = 0;
                   resultInfo.Body = result.M;
               }
           }
           catch (Exception ex)
           {
               resultInfo.Result = 0;
               resultInfo.Body = ex.Message;
           }
           return resultInfo;
       }
    }
}
